package com.base.engine.graphics;

import com.base.engine.error.VertexException;

public class VertexArray3f {

	private static int amt = 0 ; 
	
	public final int MAX_SIZE ; 
	public final String NAME ; 
	private int cnt = 0 ; 
	private int id ; 
	private VertexData3fuv[] vertices ; 
	private EDisplayMode displayMode ; 
	
	public VertexArray3f(int size, String name, EDisplayMode mode){
		MAX_SIZE = size ;
		NAME = name ; 
		vertices = new VertexData3fuv[MAX_SIZE];
		setID();
		setDisplayMode(mode);
	}
	
	public VertexArray3f(int size, String name, EDisplayMode mode, VertexData3fuv vertex){
		this(size, name, mode);
		addVertex(vertex);
	}
	
	public VertexArray3f(String name, EDisplayMode mode, VertexData3fuv[] vertices){
		this(vertices.length, name, mode); 
		addVertices(vertices);
	}
	
	private void setID(){
		id = amt++ ; 
	}
	
	public int getID(){
		return id ; 
	}
	
	public EDisplayMode getDisplayMode() {
		return displayMode;
	}

	public void setDisplayMode(EDisplayMode displayMode) {
		if(displayMode == null) this.displayMode = EDisplayMode.DM_COLORED ; 
		else this.displayMode = displayMode;
	}

	public void addVertices(VertexData3fuv[] vertices){
		if(vertices == null) VertexException.NullPointerException();
		else{
			for(VertexData3fuv v: vertices)
				addVertex(v);
		}
	}
	
	public void addVertex(VertexData3fuv vertex){
		if(vertex == null) VertexException.NullPointerException(); 
		else{
			if(!isFull()){
				vertices[cnt] = vertex ; 
				cnt++ ; 
			}
		}
	}

	public VertexData3fuv getVertex(int ID){
		return vertices[ID];
	}
	
	public VertexData3fuv[] getVertices(){
		return vertices ; 
	}
	
	public VertexData3fuv[] getVertices(int startID, int endID){
		if((startID >= 0) && (endID<cnt) && (endID >= startID)){
			int delta = endID - startID ; 
			VertexData3fuv[] tmp = new VertexData3fuv[delta] ; 
			for(int i=startID; i<=endID;i++)
				tmp[i] = getVertex(i);
			return tmp ; 
		}
		return null ; 
	}
	
	
	public boolean isFull(){
		return (cnt == MAX_SIZE); 
	}
	
	public int getSize(){
		return cnt ; 
	}
	
}
